package net.lab1024.sa.admin.module.business.core.material.controller;

import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialAddForm;
import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialQueryForm;
import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialUpdateForm;
import net.lab1024.sa.admin.module.business.core.material.domain.vo.MaterialVO;
import net.lab1024.sa.admin.module.business.core.material.service.MaterialService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * 物料信息表 Controller
 *
 * @Author ADog
 * @Date 2025-09-19 16:40:32
 * @Copyright 1.0
 */

@RestController
@Tag(name = "物料信息表")
public class MaterialController {

    @Resource
    private MaterialService materialService;

    @Operation(summary = "分页查询 @author ADog")
    @PostMapping("/material/queryPage")
    @SaCheckPermission("material:query")
    public ResponseDTO<PageResult<MaterialVO>> queryPage(@RequestBody @Valid MaterialQueryForm queryForm) {
        return ResponseDTO.ok(materialService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author ADog")
    @PostMapping("/material/add")
    @SaCheckPermission("material:add")
    public ResponseDTO<String> add(@RequestBody @Valid MaterialAddForm addForm) {
        return materialService.add(addForm);
    }

    @Operation(summary = "更新 @author ADog")
    @PostMapping("/material/update")
    @SaCheckPermission("material:update")
    public ResponseDTO<String> update(@RequestBody @Valid MaterialUpdateForm updateForm) {
        return materialService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author ADog")
    @PostMapping("/material/batchDelete")
    @SaCheckPermission("material:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return materialService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author ADog")
    @GetMapping("/material/delete/{materialId}")
    @SaCheckPermission("material:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long materialId) {
        return materialService.delete(materialId);
    }
}
